const request = require('../../utils/request')
const controller = require("../index")
const service = require("../../service/FileSystem/svgToPng")

exports.shotScreen = async (req, res) => {
    if (!req.file) return res.send(controller.errorParams({ msg: '请上传文件' }))
    try {
        const point = await request({
            url: '/do_user_points',
            method: 'post',
            data: {
                uid: req.body.uid,
                token: req.body.token,
                type: 'doum-workshop-h5:tik-tok-comment'
            }
        })
        if (point.status !== 1) {
            res.send(controller.errorParams({ msg: point.message || point.msg || '扣除积分失败' }))
            return
        }

        const data = await service.svgToPng(req.file)
        if (!data.url) {
            res.send(controller.errorParams({ msg: data.msg }))
            return
        }
        res.send(controller.successParams({ data: data.url }))
    } catch (err) {
        console.log(err)
        res.send(controller.errorParams({ msg: err }))
    }
}
